using System.Reflection;
using Blog.Infrastructure.Mappings;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
using NHibernate.Tool.hbm2ddl;

namespace Blog.Infrastructure.Configuration
{
    namespace Blog.Infrastructure.Config
    {
        public class NHibernateConfigurator
        {
            public static ISessionFactory MsSqlCeSessionFactory()
            {
                return Fluently.Configure()
                    .Database(MsSqlCeConfiguration.Standard.ConnectionString(c=>c.FromConnectionStringWithKey("ConnectionString")).ShowSql())
                    .Mappings(m => m.FluentMappings.AddFromAssembly(Assembly.Load("Blog.Infrastructure")))
                   // .ExposeConfiguration(cfg => new SchemaExport(cfg).Create(false, true))
                    .ExposeConfiguration(x => x.SetProperty("connection.release_mode", "on_close"))
                    .BuildSessionFactory();

               
            }
            
            public static ISessionFactory InMemorySessionFactory()
            {
                var config = SQLiteConfiguration.Standard.UsingFile("dbIntegration.sqlite").ShowSql();

                return Fluently.Configure()
                    .Database(config)
                    .Mappings(m => m.FluentMappings.AddFromAssemblyOf<ArticleMap>())
                    .ExposeConfiguration(cfg => new SchemaExport(cfg).Create(false, true))
                    .BuildSessionFactory();
            }
        }
    }
}